package com.jdk8.demo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Java8_Stream_Sorted {
	public static void main(String[] args) {
		List<Person> persons = new ArrayList();
		 for (int i = 1; i <= 5; i++) {
		 Person person = new Person(i, "name" + i);
		 persons.add(person);
		 }
		List<Person> personList2 = persons.stream().limit(2).sorted((p1, p2) -> p1.getName().compareTo(p2.getName())).collect(Collectors.toList());
		System.out.println(personList2);

		
	}

}
